Version 2.5 User's Guide |
|
Extending PageSentry Using AppleEvents | Previous Contents |
When a problem is detected with one of your Internet servers, PageSentry can send a notification via AppleEvents to any application you like. This application will most likely be an AppleScript that will either perform some function itself or extract the event information and send another AppleEvent to some other application.The SENTfail AppleEventFirst, here are the technical details of the AppleEvent that PageSentry sends for a notification. In order to make sense of this information, it will be best if you are familiar with using AppleScript to send and/or receive AppleEvents. If you are not, you may be able to use the examples to get started, but this chapter is not intended to be a primer on either AppleScript or AppleEvents.
The notification event PageSentry sends is called "SENTfail". (The event class is "SENT" and the specific event is "fail".) The event includes several parameters which you can extract and use in your application:Example 11. Direct - The direct arguement sent from PageSentry is the name of the Sentry that is reporting.
In almost all cases, you can start with the following simple AppleScript shell. These few lines will put the parameters passed from PageSentry into the variables "SentryName", "FailedURL", "Extra", and "Status". You can then add whatever code you like to perform the notification you need.2. Failed URL (FURL) - This is the full URL that is tested by the Sentry.
3. Status (STAT) - The status of the test will be either "OK" (if there was no error) or an error message. The error message will be the same as displayed in the Status Detail window.
4. Extra (XTRA) - This is the extra information supplied in the Notifier Editor dialog box.
--- PageSentry Notification Receiver on <<event SENTfail>> sentryName given <<class FURL>>:failedURL, <<class XTRA>>:extra, <<class STAT>>:Status --- This is where you would do your thing... end <<event SENTfail>>Important note: The code fragments on this page may not have the "<<" and ">>" symbols displayed correctly in your Web browser. Please open the "StarterApplet" file with your AppleScript script editor to get the correct text.
The following example, "DisplayDialog", will display a dialog box with the error information in it. This script is very simple, and does nothing except extract the paramaters out of the event and display a dialog box. The code looks like this:Example 2--- PageSentry Notification Applet: DisplayDialog on <<event SENTfail>> sentryName given <<class FURL>>:failedURL, <<class XTRA>>:extra, <<class STAT>>:Status display dialog "Received Sentry Event" & retur & return & "SentryName: " & sentryName & return & "failed URL: " & failedURL & return & "Extra: " & extra & return & "Status: " & Status end <<event SENTfail>>
The second example, "SendPage", is only slightly more complicated. In this case, we will be passing the data from the notification event off to another application for processing. "SendPage" requires the "Notify!" alphanumeric paging software from ExMachina in order to send pages. Install Notify! on any machine on the AppleTalk LAN along with PageSentry and this applet can be easily modified to send pages.--- PageSentry Notification Applet: Send Alphanumeric Page on <<event SENTfail>> sentryName given <<class FURL>>:failedURL, <<class XTRA>>:extra, <<class STAT>>:Status set PageCommand to "Page \"" & extra & "\" " & sentryName & "-" & Status & " " & failedURL tell application "Notify! Server" of machine "PageServer" of zone "PageServerZone" do script PageCommand end tell end <<event SENTfail>>The "set PageCommand" line builds a message that will be sent to the pager by concatenating the variables passed from PageSentry. "Tell application" is the AppleScript command to send an AppleEvent to another application, in this case, the "Notify Server" application (which may be running on another Macintosh).This example uses AppleScript as "glue" to tie PageSentry to another application. By understanding both the notification event coming from PageSentry and the paging event supported by Notify!, the applet can tie the two applications together with very little code.
This example also makes use of the "extra" parameter to specify the name of the person (as defined in Notify!) to be paged. This is just one example of how the "extra" parameter can be used to allow multiple Notifiers to use the same AppleScript applet to do slightly different things. If all of the pages were to be sent to a single recipient, we could simplify this example even more by "hard coding" the recipient's name in place of using the "extra" parameter to insert it.
If you have Notify!, and would like to use this script to allow PageSentry to page you, you only need to change the "tell application" line. Change the computer name "PageServer" to the Notify! Macintosh's machine name. You will also need to change the zone name to the name of the zone on your LAN. If Notify! is running on the same machine as PageSentry, the whole line can simply be shortened to:
tell application "Notify! Server"There is no need to specify the machine name or zone if Notify is running on the same Macintosh.
Copyright © 1995-98 Maxum Development Corporation 820 South Bartlett Road - Suite 104 Streamwood, IL 60107 http://www.maxum.com/ Rev. 2/18/98 |
Previous Contents |